package com.example.demo.service;

import com.example.demo.servlet.ThreadTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Service;

import java.util.concurrent.ScheduledFuture;


/**
 * @ClassName: DynamicTaskService
 * @Description:
 * @Author: 12071
 * @Date: 2021/6/29 20:30
 */
@Service
public class DynamicTaskService {

//    @Autowired
//    private ThreadPoolTaskScheduler threadPoolTaskScheduler;
//
//    private ScheduledFuture<?> future;
//
//    public ThreadPoolTaskScheduler threadPoolTaskScheduler(){
//        return new ThreadPoolTaskScheduler();
//    }

     private Thread thread;

    public DynamicTaskService() {
        this.thread = new ThreadTask();
    }

    public void startReceive(){
        thread.start();
        System.out.println("Service.startReceive");
    }

    public void stopReceive(){
        thread.interrupt();
        System.out.println("Service.stopReceive");
    }
}
